#include "CmdTransmitter.h"
#include "CapyTestLib/CmdReceiver.h" // For #defines.
#include <wx/wx.h>
#include <wx/socket.h>
#include <wx/stream.h>
#include <wx/sckstrm.h>
#include <wx/txtstrm.h>

class CmdTransmitterImpl
{
public:
	wxString result;

	wxSocketClient* client;
	wxSocketInputStream* sockIn;
	wxSocketOutputStream* sockOut;
	wxTextInputStream* textIn;
	wxTextOutputStream* textOut;
};

CmdTransmitter::CmdTransmitter()
{
	impl = new CmdTransmitterImpl();

	wxIPV4address addr;
	addr.Hostname(_T("127.0.0.1"));
	addr.Service(CAPY_TEST_CMD_PORT);

	impl->client = new wxSocketClient();
	if (impl->client->Connect(addr))
	{
	}
	else
	{
		// Problem.
	}
	impl->sockIn = new wxSocketInputStream(*impl->client);
	impl->textIn = new wxTextInputStream(*impl->sockIn);

	impl->sockOut = new wxSocketOutputStream(*impl->client);
	impl->textOut = new wxTextOutputStream(*impl->sockOut);
}

CmdTransmitter::~CmdTransmitter()
{
	delete impl->textOut;
	delete impl->sockOut;
	delete impl->textIn;
	delete impl->sockIn;

	impl->client->Close();

	delete impl->client;
	delete impl;
}

const wxString& CmdTransmitter::Execute(
	const wxString& component, 
	const wxString& command, 
	const wxTextOutputStream& data)
{
	return impl->result;
}
